﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Runtime.Serialization;
using CNStreaming;
using CNUtility;

namespace CNShapes
{
    /// <summary>
    /// This class is a base class for shapes that use a Pen for drawing.
    /// It holds the details of the pen.
    /// </summary>
    public abstract class ShapeBase_DrawnWithPen : Shape
    {
        #region Public methods

        /// <summary>
        /// Constructor.
        /// </summary>
        public ShapeBase_DrawnWithPen()
        {
            m_fPenWidth = UserPreferences.getPropertyBag().getFloat("DefaultPen.Width");
            int iPenColor = UserPreferences.getPropertyBag().getInt("DefaultPen.Color");
            m_PenColor = Color.FromArgb(iPenColor);
        }

        /// <summary>
        /// Returns the pen width.
        /// </summary>
        public float getPenWidth()
        {
            return m_fPenWidth;
        }

        /// <summary>
        /// Sets the pen width.
        /// </summary>
        public void setPenWidth(float penWidth, ActionOrigin actionOrigin)
        {
            m_fPenWidth = penWidth;
            raiseShapeEditedEvent(actionOrigin);
        }

        /// <summary>
        /// Gets the pen color.
        /// </summary>
        public Color getPenColor()
        {
            return m_PenColor;
        }

        /// <summary>
        /// Sets the pen color.
        /// </summary>
        public void setPenColor(Color penColor, ActionOrigin actionOrigin)
        {
            m_PenColor = penColor;
            raiseShapeEditedEvent(actionOrigin);
        }

        #endregion

        #region IStreamable members

        /// <summary>
        /// Serializes this class's data to the stream passed in.
        /// </summary>
        public override void toStream(MessageStream stream)
        {
            base.toStream(stream);
            stream.writeFloat(m_fPenWidth);
            stream.writeColor(m_PenColor);
        }

        /// <summary>
        /// Reads this object's data from the stream passed in.
        /// </summary>
        public override void fromStream(MessageStream stream, int iVersion)
        {
            base.fromStream(stream, iVersion);
            m_fPenWidth = stream.readFloat();
            m_PenColor = stream.readColor();
        }

        #endregion

        #region Protected data

        // Pen width and color...
        protected float m_fPenWidth = 3f;
        protected Color m_PenColor = Color.Blue;

        #endregion
    }
}
